package com.yfp.tissue.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.common.security.annotation.RequiresPermissions;
import com.yfp.tissue.domain.Dto.RouteDTO;
import com.yfp.tissue.domain.entity.Route;
import com.yfp.tissue.service.AreaService;
import com.yfp.tissue.service.RouteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @PROJECT_NAME: ydyfp
 * @DESCRIPTION:
 * @USER: xiaohuya
 * @DATE: 2023/12/17 14:50
 */

@RestController
@RequestMapping("/route")
@Tag(name = "路线管理")
public class RouteController extends BaseController {


    @Resource
    private RouteService routeService;

    @Resource
    private AreaService areaService;


    /**
     * 线路管理
     */
    @GetMapping("queryRoute")
    @Operation(summary = "线路管理")
    @RequiresPermissions("tissue:route:list")
    public TableDataInfo queryRoute(@RequestParam(value = "companyId", required = false) String companyId, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "contracts", required = false) String contracts, @RequestParam(value = "areaId", required = false) String cityId, @RequestParam(value = "enable", required = false) String enable) {
        RouteDTO routeDTO = new RouteDTO();
        routeDTO.setCompanyId(companyId);
        routeDTO.setRouteName(name);
        routeDTO.setCityId(cityId);
        routeDTO.setEnable(enable);
        routeDTO.setContracts(contracts);
        return getDataTable(routeService.queryRoute(routeDTO));
    }

    /**
     * 线路详情
     */
    @GetMapping("routeDetail")
    @Operation(summary = "线路查看")
    public R routeDetail(String routeId) {
        return routeService.routeDetail(routeId);
    }

    /**
     * 线路新增
     */
    @PostMapping("routeAdd")
    @Operation(summary = "线路新增")
    @Log(title = "线路新增", businessType = BusinessType.INSERT)
    @RequiresPermissions("tissue:route:add")
    public R routeAdd(@RequestBody Route route) {
        return routeService.routeAdd(route);
    }


    /**
     * 禁用
     */
    @GetMapping("routeProhibit")
    @Operation(summary = "禁用")
    @Log(title = "禁用", businessType = BusinessType.UPDATE)
    @RequiresPermissions("tissue:route:dis")
    public R addQuery(String id, String enabled) {
        return areaService.prohibit(id, "线路", enabled);

    }

    /**
     * 禁用
     */
    @PostMapping("updateRoute")
    @Operation(summary = "线路修改")
    @Log(title = "线路修改", businessType = BusinessType.UPDATE)
    @RequiresPermissions("tissue:route:edit")
    public R updateRote(@RequestBody Route route) {
        return routeService.updateRoute(route);

    }
}
